import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

public class project {
    public String reverseOnlyLetters(String s) {
        int len=s.length();
        int left=0;
        int right=len-1;
        char[] str=s.toCharArray();
        while (left<right){
            while (left<right&&!Character.isLetter(s.charAt(left))){
                left++;
            }
            while (left<right&&!Character.isLetter(s.charAt(right))){
                right--;
            }
            if(left>=right){
                break;
            }
            swap(str,left,right);
            left++;
            right--;
        }
        return new String(str);
    }
    public void swap(char[] str,int x,int y){
        char ch=str[x];
        str[x]=str[y];
        str[y]=ch;
    }
}









class StackOfPlates {
    List<Deque<Integer>> list;
    int count;
    public StackOfPlates(int cap) {
        list=new ArrayList<>();
        count=cap;
    }

    public void push(int val) {
        if(count<=0){
            return;
        }
        if(list.isEmpty()||list.get(list.size()-1).size()==count){
            list.add(new ArrayDeque<>());
        }
        list.get(list.size()-1).addFirst(val);
    }

    public int pop() {
        if(list.size()==0){
            return -1;
        }
        int tmp=list.get(list.size()-1).pollFirst();
        if(list.get(list.size()-1).size()==0){
            list.remove(list.size()-1);
        }
        return tmp;
    }

    public int popAt(int index) {
        if(index<0||index>=list.size()||list.isEmpty()){
            return -1;
        }
        int tmp=list.get(index).pollFirst();
        if(list.get(index).size()==0){
            list.remove(index);
        }
        return tmp;
    }
}